package mark.tom.fiter.bean.config;

import java.util.ArrayList;
import java.util.List;

import mark.tom.fiter.http.ssl.AbstractSSLSocketFactory;
import okhttp3.CookieJar;
import okhttp3.Dns;
import okhttp3.Interceptor;

public class OkHttpConfig {

    // 默认超时时间 15S
    private final static int DEFAULT_TIME_OUT = 15;

    // request拦截器
    private final List<Interceptor> requestInterceptors = new ArrayList<>();
    // response拦截器
    private final List<Interceptor> responseInterceptors = new ArrayList<>();
    // DNS
    private Dns dns;
    // CookieJar
    private CookieJar cookieJar;
    // 网络是否允许代理
    private boolean useProxy;
    // SSLSocketFactory
    private AbstractSSLSocketFactory sslSocketFactory;
    // 读超时时间
    private int readTimeOut = DEFAULT_TIME_OUT;
    // 写超时时间
    private int writeTimeOut = DEFAULT_TIME_OUT;
    // 链接超时时间
    private int connectTimeOut = DEFAULT_TIME_OUT;

    public List<Interceptor> getRequestInterceptors() {
        return requestInterceptors;
    }

    public OkHttpConfig addRequestInterceptors(Interceptor interceptor) {
        if (null != interceptor) {
            this.requestInterceptors.add(interceptor);
        }
        return this;
    }

    public List<Interceptor> getResponseInterceptors() {
        return responseInterceptors;
    }

    public OkHttpConfig addResponseInterceptors(Interceptor interceptor) {
        if (null != interceptor) {
            this.responseInterceptors.add(interceptor);
        }
        return this;
    }

    public Dns getDns() {
        return dns;
    }

    public OkHttpConfig setDns(Dns dns) {
        this.dns = dns;
        return this;
    }

    public boolean isUseProxy() {
        return useProxy;
    }

    public OkHttpConfig setUseProxy(boolean useProxy) {
        this.useProxy = useProxy;
        return this;
    }

    public AbstractSSLSocketFactory getSslSocketFactory() {
        return sslSocketFactory;
    }

    public OkHttpConfig setSslSocketFactory(AbstractSSLSocketFactory sslSocketFactory) {
        this.sslSocketFactory = sslSocketFactory;
        return this;
    }

    public CookieJar getCookieJar() {
        return cookieJar;
    }

    public OkHttpConfig setCookieJar(CookieJar cookieJar) {
        this.cookieJar = cookieJar;
        return this;
    }

    public OkHttpConfig setReadTimeOut(int readTimeOut) {
        this.readTimeOut = readTimeOut;
        return this;
    }

    public OkHttpConfig setWriteTimeOut(int writeTimeOut) {
        this.writeTimeOut = writeTimeOut;
        return this;
    }

    public OkHttpConfig setConnectTimeOut(int connectTimeOut) {
        this.connectTimeOut = connectTimeOut;
        return this;
    }

    public int getReadTimeOut() {
        return readTimeOut;
    }

    public int getWriteTimeOut() {
        return writeTimeOut;
    }

    public int getConnectTimeOut() {
        return connectTimeOut;
    }
}
